﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using LPV_POS.Module;
using LPV_POS.In;
using System.Resources;
using System.Globalization;

namespace LPV_POS.mh_pos.mh_inbaocao
{
    public partial class frmBaoCao_CongNo_KhachHang : DevExpress.XtraEditors.XtraForm
    {
        CultureInfo culture;

        #region "Muti language"

        private void SetLanguage_banhang(string cultureName)
        {
            try
            {
                culture = CultureInfo.CreateSpecificCulture(cultureName);
                ResourceManager rm = new ResourceManager("LPV_POS.Muti_language.MyResource", typeof(mh_banhang6_PhuThu).Assembly);
                label2.Text = rm.GetString("congnokhachhang", culture);
                label4.Text = rm.GetString("khachhang", culture);
                label1.Text = rm.GetString("sophieu", culture);
                label3.Text = rm.GetString("tungay", culture);
                label5.Text = rm.GetString("denngay", culture);
                btnIn.Text = rm.GetString("tim", culture);
                btnThoat.Text = rm.GetString("thoat", culture);
                this.col_DM_KHACHHANG_NAME.Caption = rm.GetString("khachhang", culture);
                this.COL_SO_PHIEU.Caption = rm.GetString("sophieu", culture);
                this.col_NGAY.Caption = rm.GetString("ngay", culture);
                this.col_NO_BAN_DAU.Caption = rm.GetString("nobandau", culture);
                this.col_THIEU_NO.Caption = rm.GetString("thieuno", culture);
                this.col_TRA_NO.Caption = rm.GetString("trano", culture);
                this.col_CON_LAI.Caption = rm.GetString("conlai", culture);
                this.col_DIEN_GIAI.Caption = rm.GetString("diengiai", culture);       
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Note");
            }

        }

        #endregion

        public frmBaoCao_CongNo_KhachHang()
        {
            InitializeComponent();
            culture = CultureInfo.CurrentCulture;
        }
        private void frmBaoCao_NguyenVatLieu_Load(object sender, EventArgs e)
        {
            cpublic ocpublic = new cpublic();
            string str_lang = ocpublic.Registry_Get("mh_main_lang");
            if (str_lang == "")
                str_lang = "vi-VN";
            SetLanguage_banhang(str_lang);

            this.Cursor = Cursors.WaitCursor;
            this.ShowCombo();
            this.ShowData();
            this.Cursor = Cursors.Default;
        }

        void ShowData()
        {
            string[] obj = new string[5];
            object[] value = new object[5];

            obj[0] = "@flag";
            value[0] = 4;
            
            if (txtKhachHang.Text.Trim() != "")
            {
                obj[1] = "@DM_KHACHHANG_NAME";
                value[1] = txtKhachHang.Text.Trim();
            }

            obj[2] = "@NGAY_TU";
            value[2] = dtpNgay_tu.Value;

            obj[3] = "@NGAY_DEN";
            value[3] = dtpNgay_den.Value;

            if (txtSoPhieu.Text.Trim() != "")
            {
                obj[4] = "@SO_PHIEU";
                value[4] = txtSoPhieu.Text.Trim();
            }

            DataTable tb1 = new thuvien().SP_SelectDataTable("sp_DM_CONGNO", obj, value);
            grdData.DataSource = tb1;
        }

        void ShowCombo()
        {
            dtpNgay_tu.Value = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1,0,0,0);
            dtpNgay_den.Value = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1, 23, 59, 59).AddMonths(1).AddDays(-1);
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }
        
        private void btnIn_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
            this.ShowData();
            this.Cursor = Cursors.Default;
        }

        private void btnExcel_Click(object sender, EventArgs e)
        {
            SaveFileDialog s = new SaveFileDialog();
            s.Filter += "*.xls|*.xls";
            s.FileName = "Cong_No_KH_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".xls";
            if (s.ShowDialog() == DialogResult.OK)
            {
                string FN = s.FileName;
                grvData.ExportToExcelOld(FN);
                if (System.IO.File.Exists(s.FileName))
                    System.Diagnostics.Process.Start(s.FileName);
            }
        }
    }
}